<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Query.FilterOperator" %>

<% 
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		Key accountKey = KeyFactory.createKey("AudioFiles", "mediaFiles");
		int rawByteSize;
		Query query = new Query("Audio", accountKey).
				addFilter("user", FilterOperator.EQUAL, (String)session.getAttribute("username")).
				addSort("mediaName", Query.SortDirection.ASCENDING).
				addFilter("contentType", FilterOperator.EQUAL, "application");
		List<Entity> documentlist = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));

		%>
		<h2>Sort By Collection</h2>
				<a href="/documentGallery.jsp">All Albums</a><br />
				<%
				String Check="";
				for (Entity album: documentlist) {
					Check = album.getProperty("album").toString();
					if(!album.getProperty("album").toString().equals(Check)){
					%>
					<a href="/documentGallery.jsp?album=<%= album.getProperty("album") %>"><%= album.getProperty("album") %></a><br/>
					<%
					}
					Check = album.getProperty("album").toString();
				}
				%>
				<br />
				<h2>Sort By Date</h2>
				<a href="/documentGallery.jsp">All Dates</a><br />
				<%
				for (Entity date: documentlist) {
					%>
					<a href="/documentGallery.jsp?date=<%= date.getProperty("dateCreated") %>"><%=date.getProperty("dateCreated") %></a><br/>
					<%
				}
%>